#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (int n, m; cin >> n >> m;) {
        list<int> L;
        for (int i = 1; i <= n; i++)
            L.push_back(i);
        auto p = L.begin();
        while (L.size() > 1) {
            for (int i = 1; i < m; i++) {
                p++;
                if (p == L.end())
                    p = L.begin();
            }

            p = L.erase(p);
            if (p == L.end())
                p = L.begin();
//        copy(L.begin(), L.end(), ostream_iterator<int>(cout, " "));
//        cout << endl;
        }
        cout << L.front() << endl;
    }

    return 0;
}
//stl 双向链表list 模拟循环链表
